home *** CD-ROM | disk | FTP | other *** search
/ Freelog 121 / FreelogMagazineJuilletAout2014-No121.iso / Outils / Adobe-Air / adobe-air_13.exe / [0] / setup.swf / scripts / mx / effects / EffectManager.as < prev    next >
Text File  |  2014-03-27  |  19KB  |  587 lines

  1. package mx.effects
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.DisplayObjectContainer;
  5.    import flash.events.Event;
  6.    import flash.events.EventDispatcher;
  7.    import flash.events.FocusEvent;
  8.    import flash.utils.Dictionary;
  9.    import mx.core.ApplicationGlobals;
  10.    import mx.core.EventPriority;
  11.    import mx.core.IDeferredInstantiationUIComponent;
  12.    import mx.core.IFlexDisplayObject;
  13.    import mx.core.IUIComponent;
  14.    import mx.core.UIComponent;
  15.    import mx.core.UIComponentCachePolicy;
  16.    import mx.core.mx_internal;
  17.    import mx.events.EffectEvent;
  18.    import mx.events.FlexEvent;
  19.    import mx.events.MoveEvent;
  20.    import mx.events.ResizeEvent;
  21.    import mx.resources.IResourceManager;
  22.    import mx.resources.ResourceManager;
  23.    
  24.    use namespace mx_internal;
  25.    
  26.    public class EffectManager extends EventDispatcher
  27.    {
  28.       
  29.       private static var _resourceManager:IResourceManager;
  30.       
  31.       private static var effects:Dictionary = new Dictionary(true);
  32.       
  33.       mx_internal static var effectsPlaying:Array = [];
  34.       
  35.       private static var targetsInfo:Array = [];
  36.       
  37.       mx_internal static const VERSION:String = "3.0.0.0";
  38.       
  39.       private static var effectTriggersForEvent:Object = {};
  40.       
  41.       mx_internal static var lastEffectCreated:Effect;
  42.       
  43.       private static var eventHandlingSuspendCount:Number = 0;
  44.       
  45.       private static var eventsForEffectTriggers:Object = {};
  46.        
  47.       
  48.       public function EffectManager()
  49.       {
  50.          super();
  51.       }
  52.       
  53.       public static function suspendEventHandling() : void
  54.       {
  55.          ++eventHandlingSuspendCount;
  56.       }
  57.       
  58.       mx_internal static function registerEffectTrigger(param1:String, param2:String) : void
  59.       {
  60.          var _loc3_:Number = NaN;
  61.          if(param1 != "")
  62.          {
  63.             if(param2 == "")
  64.             {
  65.                _loc3_ = param1.length;
  66.                if(_loc3_ > 6 && param1.substring(_loc3_ - 6) == "Effect")
  67.                {
  68.                   param2 = param1.substring(0,_loc3_ - 6);
  69.                }
  70.             }
  71.             if(param2 != "")
  72.             {
  73.                effectTriggersForEvent[param2] = param1;
  74.                eventsForEffectTriggers[param1] = param2;
  75.             }
  76.          }
  77.       }
  78.       
  79.       private static function removedEffectHandler(param1:DisplayObject, param2:DisplayObjectContainer, param3:int, param4:Event) : void
  80.       {
  81.          suspendEventHandling();
  82.          param2.addChildAt(param1,param3);
  83.          resumeEventHandling();
  84.          createAndPlayEffect(param4,param1);
  85.       }
  86.       
  87.       private static function createAndPlayEffect(param1:Event, param2:Object) : void
  88.       {
  89.          var _loc4_:int = 0;
  90.          var _loc5_:int = 0;
  91.          var _loc6_:int = 0;
  92.          var _loc7_:int = 0;
  93.          var _loc9_:String = null;
  94.          var _loc10_:String = null;
  95.          var _loc11_:Array = null;
  96.          var _loc12_:Array = null;
  97.          var _loc13_:Array = null;
  98.          var _loc14_:Array = null;
  99.          var _loc15_:EffectInstance = null;
  100.          var _loc3_:Effect = createEffectForType(param2,param1.type);
  101.          if(!_loc3_)
  102.          {
  103.             return;
  104.          }
  105.          if(_loc3_ is Zoom && param1.type == MoveEvent.MOVE)
  106.          {
  107.             _loc9_ = resourceManager.getString("effects","incorrectTrigger");
  108.             throw new Error(_loc9_);
  109.          }
  110.          if(param2.initialized == false)
  111.          {
  112.             if((_loc10_ = param1.type) == MoveEvent.MOVE || _loc10_ == ResizeEvent.RESIZE || _loc10_ == FlexEvent.SHOW || _loc10_ == FlexEvent.HIDE || _loc10_ == Event.CHANGE)
  113.             {
  114.                _loc3_ = null;
  115.                return;
  116.             }
  117.          }
  118.          if(_loc3_.target is IUIComponent)
  119.          {
  120.             if((_loc11_ = IUIComponent(_loc3_.target).tweeningProperties) && _loc11_.length > 0)
  121.             {
  122.                _loc12_ = _loc3_.getAffectedProperties();
  123.                _loc4_ = _loc11_.length;
  124.                _loc6_ = _loc12_.length;
  125.                _loc5_ = 0;
  126.                while(_loc5_ < _loc4_)
  127.                {
  128.                   _loc7_ = 0;
  129.                   while(_loc7_ < _loc6_)
  130.                   {
  131.                      if(_loc11_[_loc5_] == _loc12_[_loc7_])
  132.                      {
  133.                         _loc3_ = null;
  134.                         return;
  135.                      }
  136.                      _loc7_++;
  137.                   }
  138.                   _loc5_++;
  139.                }
  140.             }
  141.          }
  142.          if(_loc3_.target is UIComponent && UIComponent(_loc3_.target).isEffectStarted)
  143.          {
  144.             _loc13_ = _loc3_.getAffectedProperties();
  145.             _loc5_ = 0;
  146.             while(_loc5_ < _loc13_.length)
  147.             {
  148.                if((_loc14_ = _loc3_.target.getEffectsForProperty(_loc13_[_loc5_])).length > 0)
  149.                {
  150.                   if(param1.type == ResizeEvent.RESIZE)
  151.                   {
  152.                      return;
  153.                   }
  154.                   _loc7_ = 0;
  155.                   while(_loc7_ < _loc14_.length)
  156.                   {
  157.                      _loc15_ = _loc14_[_loc7_];
  158.                      if(param1.type == FlexEvent.SHOW && _loc15_.hideOnEffectEnd)
  159.                      {
  160.                         _loc15_.target.removeEventListener(FlexEvent.SHOW,_loc15_.eventHandler);
  161.                         _loc15_.hideOnEffectEnd = false;
  162.                      }
  163.                      _loc15_.end();
  164.                      _loc7_++;
  165.                   }
  166.                }
  167.                _loc5_++;
  168.             }
  169.          }
  170.          _loc3_.triggerEvent = param1;
  171.          _loc3_.addEventListener(EffectEvent.EFFECT_END,EffectManager.effectEndHandler);
  172.          lastEffectCreated = _loc3_;
  173.          var _loc8_:Array;
  174.          _loc4_ = (_loc8_ = _loc3_.play()).length;
  175.          _loc5_ = 0;
  176.          while(_loc5_ < _loc4_)
  177.          {
  178.             mx_internal::effectsPlaying.push(new EffectNode(_loc3_,_loc8_[_loc5_]));
  179.             _loc5_++;
  180.          }
  181.          if(_loc3_.suspendBackgroundProcessing)
  182.          {
  183.             UIComponent.suspendBackgroundProcessing();
  184.          }
  185.       }
  186.       
  187.       public static function endEffectsForTarget(param1:IUIComponent) : void
  188.       {
  189.          var _loc4_:EffectInstance = null;
  190.          var _loc2_:int = mx_internal::effectsPlaying.length;
  191.          var _loc3_:int = _loc2_ - 1;
  192.          while(_loc3_ >= 0)
  193.          {
  194.             if((_loc4_ = mx_internal::effectsPlaying[_loc3_].instance).target == param1)
  195.             {
  196.                _loc4_.end();
  197.             }
  198.             _loc3_--;
  199.          }
  200.       }
  201.       
  202.       private static function cacheOrUncacheTargetAsBitmap(param1:IUIComponent, param2:Boolean = true, param3:Boolean = true) : void
  203.       {
  204.          var _loc4_:int = 0;
  205.          var _loc5_:int = 0;
  206.          var _loc6_:Object = null;
  207.          _loc4_ = targetsInfo.length;
  208.          _loc5_ = 0;
  209.          while(_loc5_ < _loc4_)
  210.          {
  211.             if(targetsInfo[_loc5_].target == param1)
  212.             {
  213.                _loc6_ = targetsInfo[_loc5_];
  214.                break;
  215.             }
  216.             _loc5_++;
  217.          }
  218.          if(!_loc6_)
  219.          {
  220.             _loc6_ = {
  221.                "target":param1,
  222.                "bitmapEffectsCount":0,
  223.                "vectorEffectsCount":0
  224.             };
  225.             targetsInfo.push(_loc6_);
  226.          }
  227.          if(param2)
  228.          {
  229.             if(param3)
  230.             {
  231.                ++_loc6_.bitmapEffectsCount;
  232.                if(_loc6_.vectorEffectsCount == 0 && param1 is IDeferredInstantiationUIComponent)
  233.                {
  234.                   IDeferredInstantiationUIComponent(param1).cacheHeuristic = true;
  235.                }
  236.             }
  237.             else if(_loc6_.vectorEffectsCount++ == 0 && param1 is IDeferredInstantiationUIComponent && IDeferredInstantiationUIComponent(param1).cachePolicy == UIComponentCachePolicy.AUTO)
  238.             {
  239.                param1.cacheAsBitmap = false;
  240.             }
  241.          }
  242.          else
  243.          {
  244.             if(param3)
  245.             {
  246.                if(_loc6_.bitmapEffectsCount != 0)
  247.                {
  248.                   --_loc6_.bitmapEffectsCount;
  249.                }
  250.                if(param1 is IDeferredInstantiationUIComponent)
  251.                {
  252.                   IDeferredInstantiationUIComponent(param1).cacheHeuristic = false;
  253.                }
  254.             }
  255.             else if(_loc6_.vectorEffectsCount != 0)
  256.             {
  257.                if(--_loc6_.vectorEffectsCount == 0 && _loc6_.bitmapEffectsCount != 0)
  258.                {
  259.                   _loc4_ = _loc6_.bitmapEffectsCount;
  260.                   _loc5_ = 0;
  261.                   while(_loc5_ < _loc4_)
  262.                   {
  263.                      if(param1 is IDeferredInstantiationUIComponent)
  264.                      {
  265.                         IDeferredInstantiationUIComponent(param1).cacheHeuristic = true;
  266.                      }
  267.                      _loc5_++;
  268.                   }
  269.                }
  270.             }
  271.             if(_loc6_.bitmapEffectsCount == 0 && _loc6_.vectorEffectsCount == 0)
  272.             {
  273.                _loc4_ = targetsInfo.length;
  274.                _loc5_ = 0;
  275.                while(_loc5_ < _loc4_)
  276.                {
  277.                   if(targetsInfo[_loc5_].target == param1)
  278.                   {
  279.                      targetsInfo.splice(_loc5_,1);
  280.                      break;
  281.                   }
  282.                   _loc5_++;
  283.                }
  284.             }
  285.          }
  286.       }
  287.       
  288.       mx_internal static function eventHandler(param1:Event) : void
  289.       {
  290.          var _loc2_:FocusEvent = null;
  291.          var _loc3_:DisplayObject = null;
  292.          var _loc4_:int = 0;
  293.          var _loc5_:DisplayObjectContainer = null;
  294.          var _loc6_:int = 0;
  295.          if(!(param1.currentTarget is IFlexDisplayObject))
  296.          {
  297.             return;
  298.          }
  299.          if(eventHandlingSuspendCount > 0)
  300.          {
  301.             return;
  302.          }
  303.          if(param1 is FocusEvent && (param1.type == FocusEvent.FOCUS_OUT || param1.type == FocusEvent.FOCUS_IN))
  304.          {
  305.             _loc2_ = FocusEvent(param1);
  306.             if(_loc2_.relatedObject && (_loc2_.currentTarget.contains(_loc2_.relatedObject) || _loc2_.currentTarget == _loc2_.relatedObject))
  307.             {
  308.                return;
  309.             }
  310.          }
  311.          if((param1.type == Event.ADDED || param1.type == Event.REMOVED) && param1.target != param1.currentTarget)
  312.          {
  313.             return;
  314.          }
  315.          if(param1.type == Event.REMOVED)
  316.          {
  317.             if(param1.target is UIComponent)
  318.             {
  319.                if(UIComponent(param1.target).initialized == false)
  320.                {
  321.                   return;
  322.                }
  323.                if(UIComponent(param1.target).isEffectStarted)
  324.                {
  325.                   _loc4_ = 0;
  326.                   while(_loc4_ < UIComponent(param1.target)._effectsStarted.length)
  327.                   {
  328.                      if(UIComponent(param1.target)._effectsStarted[_loc4_].triggerEvent.type == Event.REMOVED)
  329.                      {
  330.                         return;
  331.                      }
  332.                      _loc4_++;
  333.                   }
  334.                }
  335.             }
  336.             _loc3_ = param1.target as DisplayObject;
  337.             if(_loc3_ != null)
  338.             {
  339.                if((_loc5_ = _loc3_.parent as DisplayObjectContainer) != null)
  340.                {
  341.                   if((_loc6_ = _loc5_.getChildIndex(_loc3_)) >= 0)
  342.                   {
  343.                      if(_loc3_ is UIComponent)
  344.                      {
  345.                         UIComponent(_loc3_).callLater(removedEffectHandler,[_loc3_,_loc5_,_loc6_,param1]);
  346.                      }
  347.                   }
  348.                }
  349.             }
  350.          }
  351.          else
  352.          {
  353.             createAndPlayEffect(param1,param1.currentTarget);
  354.          }
  355.       }
  356.       
  357.       mx_internal static function endBitmapEffect(param1:IUIComponent) : void
  358.       {
  359.          cacheOrUncacheTargetAsBitmap(param1,false,true);
  360.       }
  361.       
  362.       private static function animateSameProperty(param1:Effect, param2:Effect, param3:EffectInstance) : Boolean
  363.       {
  364.          var _loc4_:Array = null;
  365.          var _loc5_:Array = null;
  366.          var _loc6_:int = 0;
  367.          var _loc7_:int = 0;
  368.          var _loc8_:int = 0;
  369.          var _loc9_:int = 0;
  370.          if(param1.target == param3.target)
  371.          {
  372.             _loc4_ = param1.getAffectedProperties();
  373.             _loc5_ = param2.getAffectedProperties();
  374.             _loc6_ = _loc4_.length;
  375.             _loc7_ = _loc5_.length;
  376.             _loc8_ = 0;
  377.             while(_loc8_ < _loc6_)
  378.             {
  379.                _loc9_ = 0;
  380.                while(_loc9_ < _loc7_)
  381.                {
  382.                   if(_loc4_[_loc8_] == _loc5_[_loc9_])
  383.                   {
  384.                      return true;
  385.                   }
  386.                   _loc9_++;
  387.                }
  388.                _loc8_++;
  389.             }
  390.          }
  391.          return false;
  392.       }
  393.       
  394.       mx_internal static function effectFinished(param1:EffectInstance) : void
  395.       {
  396.          delete effects[param1];
  397.       }
  398.       
  399.       mx_internal static function effectsInEffect() : Boolean
  400.       {
  401.          var _loc1_:* = undefined;
  402.          var _loc2_:int = 0;
  403.          var _loc3_:* = effects;
  404.          for(_loc1_ in _loc3_)
  405.          {
  406.             return true;
  407.          }
  408.          return false;
  409.       }
  410.       
  411.       mx_internal static function effectEndHandler(param1:EffectEvent) : void
  412.       {
  413.          var _loc5_:DisplayObject = null;
  414.          var _loc6_:DisplayObjectContainer = null;
  415.          var _loc2_:IEffectInstance = param1.effectInstance;
  416.          var _loc3_:int = mx_internal::effectsPlaying.length;
  417.          var _loc4_:int = _loc3_ - 1;
  418.          while(_loc4_ >= 0)
  419.          {
  420.             if(mx_internal::effectsPlaying[_loc4_].instance == _loc2_)
  421.             {
  422.                mx_internal::effectsPlaying.splice(_loc4_,1);
  423.                break;
  424.             }
  425.             _loc4_--;
  426.          }
  427.          if(Object(_loc2_).hideOnEffectEnd == true)
  428.          {
  429.             _loc2_.target.removeEventListener(FlexEvent.SHOW,Object(_loc2_).eventHandler);
  430.             _loc2_.target.setVisible(false,true);
  431.          }
  432.          if(_loc2_.triggerEvent && _loc2_.triggerEvent.type == Event.REMOVED)
  433.          {
  434.             if((_loc5_ = _loc2_.target as DisplayObject) != null)
  435.             {
  436.                if((_loc6_ = _loc5_.parent as DisplayObjectContainer) != null)
  437.                {
  438.                   suspendEventHandling();
  439.                   _loc6_.removeChild(_loc5_);
  440.                   resumeEventHandling();
  441.                }
  442.             }
  443.          }
  444.          if(_loc2_.suspendBackgroundProcessing)
  445.          {
  446.             UIComponent.resumeBackgroundProcessing();
  447.          }
  448.       }
  449.       
  450.       mx_internal static function startBitmapEffect(param1:IUIComponent) : void
  451.       {
  452.          cacheOrUncacheTargetAsBitmap(param1,true,true);
  453.       }
  454.       
  455.       mx_internal static function setStyle(param1:String, param2:*) : void
  456.       {
  457.          var _loc3_:String = eventsForEffectTriggers[param1];
  458.          if(_loc3_ != null && _loc3_ != "")
  459.          {
  460.             param2.addEventListener(_loc3_,EffectManager.eventHandler,false,EventPriority.EFFECT);
  461.          }
  462.       }
  463.       
  464.       mx_internal static function getEventForEffectTrigger(param1:String) : String
  465.       {
  466.          var effectTrigger:String = param1;
  467.          if(eventsForEffectTriggers)
  468.          {
  469.             try
  470.             {
  471.                return eventsForEffectTriggers[effectTrigger];
  472.             }
  473.             catch(e:Error)
  474.             {
  475.                return "";
  476.             }
  477.          }
  478.          else
  479.          {
  480.             return "";
  481.          }
  482.       }
  483.       
  484.       mx_internal static function createEffectForType(param1:Object, param2:String) : Effect
  485.       {
  486.          var cls:Class = null;
  487.          var effectObj:Effect = null;
  488.          var doc:Object = null;
  489.          var target:Object = param1;
  490.          var type:String = param2;
  491.          var trigger:String = effectTriggersForEvent[type];
  492.          if(trigger == "")
  493.          {
  494.             trigger = type + "Effect";
  495.          }
  496.          var value:Object = target.getStyle(trigger);
  497.          if(!value)
  498.          {
  499.             return null;
  500.          }
  501.          if(value is Class)
  502.          {
  503.             cls = Class(value);
  504.             return new cls(target);
  505.          }
  506.          try
  507.          {
  508.             if(value is String)
  509.             {
  510.                doc = target.parentDocument;
  511.                if(!doc)
  512.                {
  513.                   doc = ApplicationGlobals.application;
  514.                }
  515.                effectObj = doc[value];
  516.             }
  517.             else if(value is Effect)
  518.             {
  519.                effectObj = Effect(value);
  520.             }
  521.             if(effectObj)
  522.             {
  523.                effectObj.target = target;
  524.                return effectObj;
  525.             }
  526.          }
  527.          catch(e:Error)
  528.          {
  529.          }
  530.          var effectClass:Class = Class(target.systemManager.getDefinitionByName("mx.effects." + value));
  531.          if(effectClass)
  532.          {
  533.             return new effectClass(target);
  534.          }
  535.          return null;
  536.       }
  537.       
  538.       mx_internal static function effectStarted(param1:EffectInstance) : void
  539.       {
  540.          effects[param1] = 1;
  541.       }
  542.       
  543.       public static function resumeEventHandling() : void
  544.       {
  545.          --eventHandlingSuspendCount;
  546.       }
  547.       
  548.       mx_internal static function startVectorEffect(param1:IUIComponent) : void
  549.       {
  550.          cacheOrUncacheTargetAsBitmap(param1,true,false);
  551.       }
  552.       
  553.       mx_internal static function endVectorEffect(param1:IUIComponent) : void
  554.       {
  555.          cacheOrUncacheTargetAsBitmap(param1,false,false);
  556.       }
  557.       
  558.       private static function get resourceManager() : IResourceManager
  559.       {
  560.          if(!_resourceManager)
  561.          {
  562.             _resourceManager = ResourceManager.getInstance();
  563.          }
  564.          return _resourceManager;
  565.       }
  566.    }
  567. }
  568.  
  569. import mx.effects.Effect;
  570. import mx.effects.EffectInstance;
  571.  
  572. class EffectNode
  573. {
  574.     
  575.    
  576.    public var factory:Effect;
  577.    
  578.    public var instance:EffectInstance;
  579.    
  580.    function EffectNode(param1:Effect, param2:EffectInstance)
  581.    {
  582.       super();
  583.       this.factory = param1;
  584.       this.instance = param2;
  585.    }
  586. }
  587.